﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Configuration.Provider;
using Formsy.Data.Interfaces;
using Formsy.Common;
using Formsy.Data.Services;


namespace Formsy.Providers.DataStore
{
    public abstract class DataStoreProvider : ProviderBase
    {
        /// <summary>
        /// Inserts entry.
        /// </summary>
        /// <returns></returns>
        public virtual IFormsyEntry InsertEntry(string formName, bool isUpdate)
        {
            if (isUpdate)
                return null;

            return HttpDataService.Instance.FormsyService.InsertEntry(formName);
        }

        /// <summary>
        /// Inserts entry.
        /// </summary>
        /// <returns></returns>
        public virtual List<IFormsyEntryData> InsertEntryData(int formId, int entryId, Dictionary<string, string> dictionary, bool isUpdate)
        {
            List<IFormsyEntryData> data;
            if (isUpdate)
                data = HttpDataService.Instance.FormsyService.UpdateEntryData(formId, entryId, dictionary);
            else
                data = HttpDataService.Instance.FormsyService.InsertEntryData(formId, entryId, dictionary);

            return data;
        }
    }



    public class DataStoreProviderCollection : ProviderCollection
    {
        // Return an instance of DataProvider
        // for a specified provider name
        new public DataStoreProvider this[string name]
        {
            get { return (DataStoreProvider)base[name]; }
        }
    }
}

